/* GUI CONVERTED from sosorp3a.p (converter v1.75) Fri Feb  2 01:27:17 2001 */
/* sosorp3a.p - subroutine for SHIPMENT HISTORY BY CUSTOMER by part (sosorp13.p)*/
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* web convert sosorp3a.p (converter v1.00) Mon Oct 06 14:22:23 1997 */
/* web tag in sosorp3a.p (converter v1.00) Mon Oct 06 14:18:46 1997 */
/*F0PN*/ /*K0MV*/
/*V8:ConvertMode=Report                                              */
/* REVISION: 5.0      LAST MODIFIED: 07/13/89   BY: MLB *B130**/
/* REVISION: 6.0      LAST MODIFIED: 10/19/90   BY: afs *D112**/
/* REVISION: 7.3      LAST MODIFIED: 06/29/93   BY: cdt *GC83**/
/* REVISION: 7.3      LAST MODIFIED: 04/10/96   BY: jzw *G1P6**/
/* REVISION: 8.6      LAST MODIFIED: 10/07/97   BY: mur *K0MV**/
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 07/05/98   BY: *L024* Sami Kureishy*/
/* REVISION: 8.6E     LAST MODIFIED: 08/12/99   BY: *L0GK* Santosh Rao    */
/* REVISION: 9.1      LAST MODIFIED: 06/29/00   BY: *N0DX* Rajinder Kamra */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* myb                  */
/* REVISION: 9.1      LAST MODIFIED: 10/10/00   BY: *N0WC* Mudit Mehta  */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

/*G1P6*/ {mfdeclre.i}
/*N0WC*/ {cxcustom.i "SOSORP3A.P"}
/*N0DX*/ {gplabel.i}

         /* ********** Begin Translatable Strings Definitions ********* */

         &SCOPED-DEFINE sosorp3a_p_1 "Day/Week/Month"
         /* MaxLen: Comment: */

         &SCOPED-DEFINE sosorp3a_p_2 "Per Column"
         /* MaxLen: Comment: */

/*N0DX
 *         &SCOPED-DEFINE sosorp3a_p_3 "Customer Totals: "
 *         /* MaxLen: Comment: */
 *
 *         &SCOPED-DEFINE sosorp3a_p_4 "  Total Qty"
 *         /* MaxLen: Comment: */
 *
 *         &SCOPED-DEFINE sosorp3a_p_5 "Total Sales"
 *         /* MaxLen: Comment: */
 *
 *         &SCOPED-DEFINE sosorp3a_p_6 "REPORT TOTALS: "
 *         /* MaxLen: Comment: */
 *N0DX*/

           /* ********** End Translatable Strings Definitions ********* */

/*K0MV*/ {wbrp02.i}

         define shared variable start like ro_start.
         define shared variable ending like  ro_end.
         define shared variable cust like tr_addr.
         define shared variable cust1 like tr_addr.
         define shared variable dwm as character format "!(1)" label {&sosorp3a_p_1}.
         define shared variable idays as integer format ">>>>>9" label {&sosorp3a_p_2}.
         define shared variable type like cm_type.
         define shared variable type1 like cm_type.
         define shared variable region like cm_region.
         define shared variable region1 like cm_region.
         define shared variable slspsn like sp_addr.
         define shared variable slspsn1 like slspsn.
         define shared variable base_rpt like so_curr.
/*G1P6*  initial "Base" format "x(4)". */
/*D112*/ define shared variable round_1000 like mfc_logical.

         define variable interval as integer extent 14 format "->>>,>>9".
         define variable sdate as date extent 14.
         define variable salesqty as decimal extent 14 format "->>>>>>>9".
         define variable salesdol as decimal extent 14 format "->>>>>>>9".
         define variable partqty as decimal extent 14 format "->>>>>>>9".
         define variable partdol as decimal extent 14 format "->>>>>>>9".
         define variable due_date like tr_date.
         define variable i as integer.
         define variable j as integer.
         define variable monthend as integer.
         define variable num_intervals as integer initial 13 format "9".
         define variable tot_qty as decimal format "->>>>>>>>9".
         define variable tot_dol as decimal format "->>>>>>>>9".
         define variable part_tot_qty as decimal format "->>>>>>>>9".
         define variable part_tot_dol as decimal format "->>>>>>>>9".
         define variable first_cust like mfc_logical.
         define variable old_part like tr_part.
         define variable old_desc like pt_desc1.
         define variable old_um like tr_um.
         define variable base_price like tr_price.
/*L024*/ define variable mc-error-number like msg_nbr no-undo.
/*N0DX*/ define variable disp_char3 as character      no-undo.
/*N0DX*/ define variable disp_char4 as character      no-undo.
/*N0DX*/ define variable disp_char5 as character      no-undo.
/*N0DX*/ define variable disp_char6 as character      no-undo.

/*N0DX START ADD*/
   assign disp_char3 = getTermLabel("CUSTOMER_TOTALS",35) + ": ":U
          disp_char4 = getTermLabelRt("TOTAL_QTY",12)
          disp_char5 = getTermLabelRt("TOTAL_SALES",12)
          disp_char6 = caps(getTermLabel("REPORT_TOTALS",34)) + ":":U.
/*N0DX END ADD*/

   /* COMPUTE START DATES */
   sdate[1] = low_date.
   {mfcsdate.i}

   display
   sdate[2] space(2) sdate[3] space(2)
   sdate[4] space(2) sdate[5] space(2)
   sdate[6] space(2) sdate[7] space(2)
   sdate[8] space(2) sdate[9] space(2)
   sdate[10] space(2) sdate[11] space(2)
   sdate[12] space(2) sdate[13] space(2)
/*N0DX   {&sosorp3a_p_4} skip */
/*N0DX*/ disp_char4 format "x(12)" skip
   sdate[3] - 1 space(2) sdate[4] - 1 space(2)
   sdate[5] - 1 space(2) sdate[6] - 1 space(2)
   sdate[7] - 1 space(2) sdate[8] - 1 space(2)
   sdate[9] - 1 space(2) sdate[10] - 1 space(2)
   sdate[11] - 1 space(2) sdate[12] - 1 space(2)
   sdate[13] - 1 space(2) sdate[14] - 1 space(2)
/*N0DX   {&sosorp3a_p_5} skip */
/*N0DX*/ disp_char5 format "x(12)" skip
   "--------- --------- --------- --------- --------- --------- ---------"
   "--------- --------- --------- --------- --------- -----------" skip
   with frame b no-labels width 132 page-top no-box STREAM-IO /*GUI*/ .

/*G1P6*  view frame phead. */

   for each cm_mstr where (cm_addr >= cust and cm_addr <= cust1)
   and (cm_region >= region and cm_region <= region1)
   and (cm_type >= type and cm_type <= type1)
   and (cm_slspsn[1] >= slspsn and cm_slspsn[1] <= slspsn1) no-lock
   by cm_addr with frame c width 132 no-box:


      /* INITIALIZE VARIABLES */
      do i = 1 to num_intervals + 1:
     salesqty[i] = 0.
     salesdol[i] = 0.
     partqty[i] = 0.
     partdol[i] = 0.
      end.
      part_tot_qty = 0.
      part_tot_dol = 0.

      /* CALCULATE SHIPMENTS   FOR EACH INTERVAL */
      tot_qty = 0.
      tot_dol = 0.
      first_cust = yes.
      old_part = ?.
      old_desc = "".

/*N0WC*/ {&SOSORP3A-P-TAG1}
      for each tr_hist where tr_addr = cm_addr
      and (tr_type = "ISS-SO" or tr_type = "RCT-SOR")
      and (tr_effdate >= sdate[2] and tr_effdate < sdate[14])
      AND ( LOOKUP(tr_site,GLOBAL_user_site) > 0)       /*fdn*/
/*G1P6*  and ((base_rpt = "base") */
/*G1P6*/ and ((base_rpt = "")
     or (tr_curr = base_rpt))
      no-lock
/*N0WC*/ {&SOSORP3A-P-TAG2}
      use-index tr_addr_eff
      by tr_part:
     if first_cust then do:
        if page-size - line-counter < 3 then page.
        display
        cm_addr cm_sort skip
        with frame d no-labels width 132 STREAM-IO /*GUI*/ .
        first_cust = no.
     end.
     if (old_part <> tr_part) and old_part <> ? then do:
        old_desc = "".
        find pt_mstr where pt_part = old_part no-lock no-error.
        if available pt_mstr then old_desc = pt_desc1.

/*GC83*/    /* Added round_1000 logic for detail loop. */
        if round_1000 then do:
           do i = 1 to num_intervals + 1:
          partdol[i] = round(partdol[i] / 1000, 0).
           end.
           part_tot_dol = round(part_tot_dol / 1000, 0).
        end.
/*GC83*/    /* End of round_1000 logic for detail loop. */

        display old_part old_desc old_um skip
        partqty[2 for 12] part_tot_qty skip
        partdol[2 for 12] part_tot_dol skip
        with frame e no-labels width 132 STREAM-IO /*GUI*/ .
        do i = 1 to num_intervals + 1:
           partqty[i] = 0.
           partdol[i] = 0.
        end.
        part_tot_qty = 0.
        part_tot_dol = 0.
     end.
     base_price = tr_price.
/*G1P6*/ if base_rpt <> ""
         and tr_curr <> base_curr then
/*L0GK*/ do:
/*L024*     base_price = base_price * tr_ex_rate.*/
/*L024*/    {gprunp.i "mcpl" "p" "mc-curr-conv"
                         "(input base_curr,
                           input tr_curr,
                           input tr_ex_rate2,
                           input tr_ex_rate,
                           input base_price,
                           input false,
                           output base_price,
                           output mc-error-number)"}.
/*L0GK*/ end. /* IF BASE_RPT <> "" AND .. */
/*L024*/ if mc-error-number <> 0 then do:
/*L024*/    {mfmsg.i mc-error-number 2}
/*L024*/ end.

     old_part = tr_part.
     old_um = tr_um.
     due_date = tr_effdate.
     tot_qty = tot_qty - tr_qty_loc.
     tot_dol = tot_dol - (base_price * tr_qty_loc).
     part_tot_qty = part_tot_qty - tr_qty_loc.
     part_tot_dol = part_tot_dol - (base_price * tr_qty_loc).
     do i = num_intervals + 1 to 1 by -1:
        if due_date >= sdate[i] then do:
           salesqty[i] = salesqty[i] - tr_qty_loc.
           salesdol[i] = salesdol[i] - (base_price * tr_qty_loc).
           partqty[i] = partqty[i] - tr_qty_loc.
           partdol[i] = partdol[i] - (base_price * tr_qty_loc).
           leave.
        end.
     end.
      end.

      /*END SECTION*/

      if first_cust = no then do:

     find pt_mstr where pt_part = old_part no-lock no-error.
     if available pt_mstr then old_desc = pt_desc1.
      else old_desc = "".

     if round_1000 then do:
        do i = 1 to num_intervals + 1:
           partdol[i] = round(partdol[i] / 1000, 0).
           salesdol[i] = round(salesdol[i] / 1000, 0).
        end.
        part_tot_dol = round(part_tot_dol / 1000, 0).
        tot_dol      = round(tot_dol      / 1000, 0).
     end.

     accumulate salesqty(total).
     accumulate salesdol(total).
     accumulate tot_qty(total).
     accumulate tot_dol(total).

     display old_part old_desc old_um skip
      partqty[2 for 12] part_tot_qty skip
      partdol[2 for 12] part_tot_dol skip
     with frame f no-labels width 132 STREAM-IO /*GUI*/ .
     old_part = ?.
/*N0DX   display {&sosorp3a_p_3} skip */
/*N0DX*/ display disp_char3 format "x(37)" skip
      salesqty[2 for 12] tot_qty skip
      salesdol[2 for 12] tot_dol
     with frame g no-labels width 132 STREAM-IO /*GUI*/ .
      end.
      
/*GUI*/ {mfguirex.i } /*Replace mfrpexit*/

   end.
/*N0DX   display skip(1) {&sosorp3a_p_6} skip */
/*N0DX*/ display skip(1) disp_char6 format "x(35)" skip
   accum total salesqty[2] format "->>>>>>>9"
   accum total salesqty[3] format "->>>>>>>9"
   accum total salesqty[4] format "->>>>>>>9"
   accum total salesqty[5] format "->>>>>>>9"
   accum total salesqty[6] format "->>>>>>>9"
   accum total salesqty[7] format "->>>>>>>9"
   accum total salesqty[8] format "->>>>>>>9"
   accum total salesqty[9] format "->>>>>>>9"
   accum total salesqty[10] format "->>>>>>>9"
   accum total salesqty[11] format "->>>>>>>9"
   accum total salesqty[12] format "->>>>>>>9"
   accum total salesqty[13] format "->>>>>>>9"
   accum total tot_qty format "->>>>>>>>>9" skip


   accum total salesdol[2] format "->>>>>>>9"
   accum total salesdol[3] format "->>>>>>>9"
   accum total salesdol[4] format "->>>>>>>9"
   accum total salesdol[5] format "->>>>>>>9"
   accum total salesdol[6] format "->>>>>>>9"
   accum total salesdol[7] format "->>>>>>>9"
   accum total salesdol[8] format "->>>>>>>9"
   accum total salesdol[9] format "->>>>>>>9"
   accum total salesdol[10] format "->>>>>>>9"
   accum total salesdol[11] format "->>>>>>>9"
   accum total salesdol[12] format "->>>>>>>9"
   accum total salesdol[13] format "->>>>>>>9"
     accum total tot_dol format "->>>>>>>>>9"
   with frame h no-labels width 132 no-box STREAM-IO /*GUI*/ .
/*K0MV*/ {wbrp04.i}
